/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.vrangogym.persistence.entities;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity for a workout session
 * @author habbbe
 * 
 * @revidedBy Ulken (2011-10-16)
 */
@Entity
public class WorkoutSession implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Temporal(TemporalType.TIMESTAMP)
    private Date startTime;
    @Temporal(TemporalType.TIMESTAMP)
    private Date endTime;

    /**
     * Instantiate a new workout session
     */
    public WorkoutSession() {
    }
    
    /**
     * Instantiate a new workout session
     * @param startTime the start time
     * @param endTime the end time
     */
    public WorkoutSession(Date startTime, Date endTime) {
        this.startTime = startTime;
        this.endTime = endTime;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final WorkoutSession other = (WorkoutSession) obj;
        if (this.startTime != other.startTime && (this.startTime == null || !this.startTime.equals(other.startTime))) {
            return false;
        }
        if (this.endTime != other.endTime && (this.endTime == null || !this.endTime.equals(other.endTime))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 53 * hash + (this.startTime != null ? this.startTime.hashCode() : 0);
        hash = 53 * hash + (this.endTime != null ? this.endTime.hashCode() : 0);
        return hash;
    }



    @Override
    public String toString() {
        SimpleDateFormat format = new SimpleDateFormat("HH:mm");
        return format.format(startTime) + "-->" + format.format(endTime);
    }
}
